//
//  MileageTableViewCell.m
//  Cycling
//
//  Created by 迟国强 on 2023/3/28.
//

#import "MileageTableViewCell.h"
#import "MileageRingView.h"

@implementation MileageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
    if (highlighted) {
        self.contentView.backgroundColor = COLOR_WHITE;
    }else{
        self.contentView.backgroundColor = COLOR_WHITE;
    }
    [super setHighlighted:highlighted animated:animated];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    self.titleLB = [[UILabel alloc] init];
    self.titleLB.font = FONT_SECONDARY_TITLE;
    self.titleLB.textColor = COLOR_BLACK;
    [self.contentView addSubview:self.titleLB];
    [self.titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(30);
        make.left.equalTo(self.contentView).offset(MARGIN_MAX);
//        make.top.equalTo(self.contentView).offset(15);
        make.centerY.equalTo(self.contentView);
    }];
    
    self.ringView = [[MileageRingView alloc] init];
    self.ringView.backgroundColor = UIColor.clearColor;
    [self.contentView addSubview:self.ringView];
    [self.ringView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(80, 80));
        make.right.equalTo(self.contentView).offset(-40);
//        make.bottom.equalTo(self.contentView).offset(-MARGIN_MIDDLE);
        make.centerY.equalTo(self.contentView);
    }];

//    UIView *view1 = [[UIView alloc] init];
//    view1.backgroundColor = COLOR_DISABLEED;
//    [self.contentView addSubview:view1];
//    self.leftview = view1;
//    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(20, 10));
//        make.left.equalTo(self.contentView).offset(24);
//        make.centerY.mas_equalTo(self.ringView.mas_centerY);
//    }];
//    self.lable1 = [[UILabel alloc] init];
//    self.lable1.font = FONT_BODY_15;
//    self.lable1.textColor = COLOR_BLACK;
//    [self.contentView addSubview:self.lable1];
//    [self.lable1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(20);
//        make.centerY.mas_equalTo(view1.mas_centerY);
//        make.left.equalTo(view1.mas_right).offset(8);
//        make.right.equalTo(self.ringView.mas_left).offset(-8);
//    }];
    
}


-(void)setTodayArr:(TodayArr *)todayArr {
    _todayArr = todayArr;
    self.titleLB.text = [NSString stringWithFormat:CycLocalizedString(@"Goal:%ldMiles", @"目标：%ldMiles"),(NSInteger)([todayArr.todaytj integerValue]/1609.344)];
    if ([todayArr.complete intValue] == 1) {
        if ([todayArr.todaydistance intValue] == [todayArr.todaytj intValue]) {
            self.lable1.text = [NSString stringWithFormat:@"完成%ld英里(完成)",(NSInteger)([todayArr.todaytj integerValue]/1609.344)];
            self.leftview.backgroundColor = COLOR_TOPIC_SELECT;
        }else {
            self.lable1.text = [NSString stringWithFormat:@"超过%ld公里(%.3f英里)",(NSInteger)([todayArr.todaytj integerValue]/1609.344),[todayArr.todaydistance floatValue]/1000.0];
            
            CAGradientLayer *gradientLayer = [CAGradientLayer layer];
            gradientLayer.frame = CGRectMake(0, 0, 20, 10);
            // 设置渐变颜色数组
            gradientLayer.colors = @[(__bridge id)rgbHex(0x00e0a7,1.0).CGColor, (__bridge id)rgbHex(0x00bdff,1.0).CGColor];
            gradientLayer.startPoint = CGPointMake(0.0, 0);
            gradientLayer.endPoint = CGPointMake(1.0, 0);
            [self.leftview.layer addSublayer:gradientLayer];

        }
    }
    if ([todayArr.complete intValue] == 2) {
        self.lable1.text = [NSString stringWithFormat:@"未达标(%.3f英里)",[todayArr.todaydistance floatValue]/1609.344];
        self.leftview.backgroundColor = COLOR_DISABLEED;
    }

    [self.ringView setCurrentDistance:[todayArr.todaydistance floatValue] allDistance:[todayArr.todaytj floatValue] comple:[todayArr.complete floatValue]];
}

@end
